//
//  DDMyQuestionDetailTempViewController.m
//  dingdang
//
//  Created by Chen Jing on 15-7-28.
//  Copyright (c) 2015年 阮 沧晖. All rights reserved.
//

#import "DDMyQuestionDetailTempViewController.h"
#import "MJRefresh.h"
#import "DDMyQuestionDetailCollectionViewCell.h"
#import "DDNetWorkAPIClient.h"
#import "DDMyQuestionDetailCollectionReusableView.h"
#import "DDQuestionAnswerReply.h"
#import "DDQuestionAnswerList.h"
#import "DateUtil.h"
#import "UIImageView+WebCache.h"
#import "CWStarRateView.h"
#import "DDQuestionFollowAnswerViewController.h"

#import "MWPhotoBrowser.h"
#import "MWPhoto.h"

#import "DDTagTextVC.h"

@interface DDMyQuestionDetailTempViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,DDMyQuestionDetailCollectionViewCellDelegate,CWStarRateViewDelegate,UIAlertViewDelegate,DDMyQuestionDetailCollectionReusableViewDelegate,MWPhotoBrowserDelegate>{
    DDNetWorkAPIClient * client;
    NSMutableParagraphStyle *paragraphStyle;
    NSMutableArray * array_showList;
    NSRange timeRange;
    DDSharedUser * shareUser;
    CWStarRateView * starRateView;
    DDQuestionAnswerListCell * hold_followAnswer;
    DDQuestionAnswerListCell * hold_rating;
    DDQuestionAnswerListCell * hold_adopt;
    NSInteger choosedStars;
    NSInteger currentPage;
    NSInteger total;

    NSString * holdString_PhotoBrowser;
}
@property (weak, nonatomic) IBOutlet UICollectionView *myCollectionView;
@property (weak, nonatomic) IBOutlet UIView *contentOfStarRateView;
@property (weak, nonatomic) IBOutlet UIView *contentOfAlert;
@property (weak, nonatomic) IBOutlet UIView *contentOfAlertInter;


@property (nonatomic,strong)NSMutableArray *photos;
@end

@implementation DDMyQuestionDetailTempViewController

-(void)viewWillAppear:(BOOL)animated{
    [self.myCollectionView footerBeginRefreshing];
    starRateView = [[CWStarRateView alloc]initWithFrame:self.contentOfStarRateView.bounds numberOfStars:5];
    starRateView.delegate = self;
    choosedStars = 5;
    [self.contentOfStarRateView addSubview:starRateView];
    
    
}



- (void)viewDidLoad {
    
    // Do any additional setup after loading the view from its nib.
    [self.myCollectionView addFooterWithTarget:self action:@selector(getData)];

    self.myCollectionView.headerPullToRefreshText = @"下拉可以刷新了";
    self.myCollectionView.headerReleaseToRefreshText = @"松开马上刷新了";
    self.myCollectionView.headerRefreshingText = @"别再拉了,裤子要被拉下来了...";

    self.myCollectionView.footerPullToRefreshText = @"上提可以刷新了";
    self.myCollectionView.footerReleaseToRefreshText = @"松开马上刷新了";
    self.myCollectionView.footerRefreshingText = @"别再拉了,裤子要被拉下来了...";

    [self.myCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([DDMyQuestionDetailCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([DDMyQuestionDetailCollectionViewCell class])];
    [self.myCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([DDMyQuestionDetailCollectionReusableView class]) bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([DDMyQuestionDetailCollectionReusableView class])];

    self.myCollectionView.backgroundColor = self.view.backgroundColor;
    client = [[DDNetWorkAPIClient alloc]init];
    [self createData];
    self.contentOfAlertInter.layer.cornerRadius = 10;
    self.contentOfAlertInter.layer.masksToBounds = YES;
    
    //ruanch - 标签切换图
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(displayMediaPP:) name:@"displayMediaPP" object:nil];
   
[super viewDidLoad];
}
//ruanch -标签切换图
-(void)displayMediaPP:(NSNotification *)note
{
    NSDictionary *dict = (NSDictionary*)note.object;
    NSString *type =[dict objectForKey:@"type"];
    if ( [type isEqualToString:@"TEXT"]) {
        DDTagTextVC *tagTextVC = [[DDTagTextVC alloc]initWithNibName:@"DDTagTextVC" bundle:nil];
        tagTextVC.isNonDisplay = YES;
        tagTextVC.textTF.text = [dict objectForKey:@"title"];
        [tagTextVC setTextResult:[dict objectForKey:@"title"]];
        //[tagTextVC setTextResult:[dict objectForKey:@"result"]];
        [self.navigationController pushViewController:tagTextVC animated:YES];
    }
    else if ([type isEqualToString:@"IMAGE"])
    {
        NSString *url = [dict objectForKey:@"url"];
        //MWPhoto   *photo = [MWPhoto photoWithURL:[NSURL URLWithString:url]];
        //photo.caption = _friendInfo.username;
        //_photos = @[photo];
        
        holdString_PhotoBrowser = url;
        
        // Create browser
        MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
        browser.zoomPhotosToFill = YES;
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
        browser.wantsFullScreenLayout = YES;
#endif
        browser.enableSwipeToDismiss = YES;
        [browser setCurrentPhotoIndex:0];
        [self.navigationController pushViewController:browser animated:YES];
    }
}


-(void)createData{
    paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 1;

    array_showList = [[NSMutableArray alloc]init];
    timeRange.location = 0;
    timeRange.length = 19;
    shareUser = [DDSharedUser shared];
    currentPage = 0;
}

-(void)getData{
    if (array_showList.count < total || array_showList.count == 0) {
        [self showHUD:@"请稍后..."];
        __weak DDMyQuestionDetailTempViewController * myVC = self;
        NSDictionary * tempDic = @{@"topicId":self.info_element.info_id,@"qid":self.info_detailInfo.info_id,@"pageIndex":[NSNumber numberWithInteger:currentPage],@"pageSize":[NSNumber numberWithInteger:1000000],@"excludedUid":[NSNumber numberWithInteger:-1]};
        [client mainQuestionAnswerList:tempDic completionBlock:^(BOOL isSuccess, NSString *message, NSString *status, id object) {
            [myVC.myCollectionView footerEndRefreshing];
            DDQuestionAnswerList *mylist = (DDQuestionAnswerList*)object;
            [array_showList addObjectsFromArray:mylist.list];
            [myVC.myCollectionView reloadData];
            total = mylist.total.integerValue;
            [myVC hideHUD];
            currentPage++;
        }];
    }else{
        [self.myCollectionView footerEndRefreshing];
    }
}

-(void)refreshData{
    [self showHUD:@"请稍后..."];
    currentPage = 0;
    __weak DDMyQuestionDetailTempViewController * myVC = self;
    NSDictionary * tempDic = @{@"topicId":self.info_element.info_id,@"qid":self.info_detailInfo.info_id,@"pageIndex":[NSNumber numberWithInteger:currentPage],@"pageSize":[NSNumber numberWithInteger:1000000],@"excludedUid":[NSNumber numberWithInteger:-1]};
    [client mainQuestionAnswerList:tempDic completionBlock:^(BOOL isSuccess, NSString *message, NSString *status, id object) {
        [myVC.myCollectionView footerEndRefreshing];
        
        DDQuestionAnswerList *mylist = (DDQuestionAnswerList*)object;
        [array_showList removeAllObjects];
        [array_showList addObjectsFromArray:mylist.list];
        [myVC.myCollectionView reloadData];
        total = mylist.total.integerValue;
        [myVC hideHUD];
        currentPage++;
    }];

}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (kind == UICollectionElementKindSectionHeader) {
        DDMyQuestionDetailCollectionReusableView * tempView =  [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([DDMyQuestionDetailCollectionReusableView class]) forIndexPath:indexPath];
        tempView.info_detail = self.info_detailInfo;
        tempView.info_element = self.info_element;
        tempView.delegate = self;
        [tempView fixView];
        return tempView;
    }else{
        return nil;
    }

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return array_showList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DDMyQuestionDetailCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([DDMyQuestionDetailCollectionViewCell class]) forIndexPath:indexPath];

    float tempHeight = 60.0;

    DDQuestionAnswerListCell * element = array_showList[indexPath.row];
    cell.label_userName.text = element.userName;
    [cell.imageView_head sd_setImageWithURL:[NSURL URLWithString:element.userAvatarUrl] placeholderImage:[UIImage imageNamed:@"个人中心-人数统计头像"]];
    cell.label_time.text = element.answerTime;
    
    
    
    cell.label_body.hidden = YES;
    if (element.answer) {
//        tempHeight += 30;
        cell.label_body.text = element.answer;
        cell.label_body.hidden = NO;
        
    }

    
    for (DDQuestionAnswerExplanation * explan in element.explanation) {
        if ([explan.type isEqualToString:@"TEXT"]) {
            
            if (cell.label_body.hidden == YES) {
                cell.label_body.text = explan.text;
                
                cell.label_body.hidden = NO;
            }
            
//            tempHeight += 30;
            
            if (cell.label_body.hidden == NO) {
                tempHeight += 30;
                CGRect body_tempRect = [explan.text boundingRectWithSize:CGSizeMake(CGRectGetWidth([[UIScreen mainScreen] bounds]) - 16, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin  attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14],NSParagraphStyleAttributeName : paragraphStyle} context:nil];
                float body_addHeight = body_tempRect.size.height > 20 ? body_tempRect.size.height - 20 : 20;
                
                tempHeight = body_addHeight + tempHeight + 20;
                NSLog(@"%f",CGRectGetWidth([[UIScreen mainScreen] bounds]));
                cell.label_body.frame = CGRectMake(8, 65,cell.contentView.frame.size.width - 16,body_addHeight + 20);
                
            }

        }else if ([explan.type isEqualToString:@"IMAGE"]){
//            cell.imageView_body.frame = CGRectMake(8, tempHeight, cell.contentView.frame.size.width - 16, cell.imageView_body.frame.size.height);
//            [cell.imageView_body sd_setImageWithURL:[NSURL URLWithString:explan.url] placeholderImage:[UIImage imageNamed:@"首页-答疑-客观题-单选习题拍照图-通用"]];
            
            //标签 ruanch-增加
            NSURL *url = [NSURL URLWithString:explan.url];
            UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
            cell.imageView_body.frame = CGRectMake(8, tempHeight, cell.contentView.frame.size.width - 16, cell.imageView_body.frame.size.height);
            cell.imageView_body.userInteractionEnabled = YES;
            cell.imageView_body.isOnlyRead = YES;
            cell.imageView_body.url = explan.url;
            [cell.imageView_body sd_setImageWithURL:[NSURL URLWithString:explan.url] placeholderImage:[UIImage imageNamed:@"首页-答疑-客观题-单选习题拍照图-通用"]options:SDWebImageRefreshCached];
            for (UIView *view in cell.imageView_body.subviews) {
                [view removeFromSuperview];
            }
            for (DDQuestionAnswerReplyContentLabel *labelInfo in explan.labels) {
                double c_x = ([labelInfo.x integerValue]/image.size.width)*(cell.contentView.frame.size.width - 20);
                double c_y = ([labelInfo.y integerValue]/image.size.height)*100;
                [cell.imageView_body addMedia:labelInfo.text type:labelInfo.type x:c_x y:c_y url:labelInfo.url];
            }
            //[cell addSubview:cell.imageView_body];
            //标签 ruanch-end
            
            
            
            tempHeight += 140;
            
        }
    }

    

    cell.contentOfBottom.frame = CGRectMake(0, tempHeight, CGRectGetWidth([[UIScreen mainScreen] bounds]), 30);
    cell.btn_openOrCloseFollowAnswer.frame = CGRectMake(CGRectGetWidth([[UIScreen mainScreen]bounds]) - 40, tempHeight - 30, 30, 30);


//    if (element.adopted.boolValue == YES) {
//        cell.backgroundColor = [UIColor redColor];
//    }else{
//        cell.backgroundColor = [UIColor whiteColor];
//    }

    cell.btn_bottom_followAsk.hidden =
    cell.btn_bottom_adopt.hidden =
    cell.btn_bottom_rating.hidden = NO;
    
    if (self.isReward == YES) {
        if (element.adopted) {
            cell.info_adopt = element.adopted;
            cell.btn_bottom_adopt.hidden = YES;
        }else{
            cell.info_adopt = nil;
            cell.btn_bottom_adopt.hidden = NO;
        }
    }else{
        cell.btn_bottom_adopt.hidden = YES;
    }

    if (element.score) {
        cell.info_starRating = element.score.integerValue;
        //            [cell.contentOfBottom bringSubviewToFront:cell.contentOfBottom_followAnswer];
        cell.btn_bottom_rating.hidden = YES;
    }else{
        cell.info_starRating = 0;
        //            [cell.contentOfBottom bringSubviewToFront:cell.contentOfBottom_ratingAndAnswer];
        cell.btn_bottom_rating.hidden = NO;
    }

    


//    if (element.score) {
//        cell.info_starRating = element.score.integerValue;
//        [cell.contentOfBottom bringSubviewToFront:cell.contentOfBottom_followAnswer];
//    }else{
//        cell.info_starRating = 0;
//        [cell.contentOfBottom bringSubviewToFront:cell.contentOfBottom_ratingAndAnswer];
//    }

    if (shareUser.userInfo.uid.integerValue == element.uid.integerValue) {
        cell.contentOfBottom.hidden = YES;

    }else{
        cell.contentOfBottom.hidden = NO;
    }

    if (element.info_isShowList.boolValue == YES) {
        [cell.btn_openOrCloseFollowAnswer setImage:[UIImage imageNamed:@"上三角"] forState:UIControlStateNormal];
    }else{
        [cell.btn_openOrCloseFollowAnswer setImage:[UIImage imageNamed:@"下三角"] forState:UIControlStateNormal];
    }

    cell.isOpenFollowAsk = element.info_isShowList.boolValue;
    cell.info_followAskList = element.info_exFollowAsk;
    cell.delegate = self;
    [cell fixCell];
    return cell;
}

//-(void)addTag:(UIView *)tempView model:(DDQuestionAnswerReplyContent *)content postion:(NSInteger)addHeight
//{
//    //标签 ruanch-增加
//    NSURL *url = [NSURL URLWithString:content.url];
//    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
//    DDMediaIV *imageView_body = [[DDMediaIV alloc] initWithFrame:CGRectMake(10, 60 + addHeight , CGRectGetWidth([[UIScreen mainScreen] bounds]) - 20, 200)];
//    imageView_body.userInteractionEnabled = YES;
//    imageView_body.isOnlyRead = YES;
//    imageView_body.url = content.url;
//    [imageView_body sd_setImageWithURL:[NSURL URLWithString:content.url] placeholderImage:[UIImage imageNamed:@"首页-答疑-客观题-单选习题拍照图-通用"]options:SDWebImageRefreshCached];
//    for (DDQuestionAnswerReplyContentLabel *labelInfo in content.labels) {
//        double c_x = ([labelInfo.x integerValue]/image.size.width)*(tempView.frame.size.width - 20);
//        double c_y = ([labelInfo.y integerValue]/image.size.height)*300;
//        
//        [imageView_body addMedia:labelInfo.text type:labelInfo.type x:c_x y:c_y url:labelInfo.url];
//    }
//    //标签 ruanch end
//    [tempView addSubview:imageView_body];
//}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGSize tempSize;
    CGFloat addHeight = 30.0;
    DDQuestionAnswerListCell * element = array_showList[indexPath.row];
    if (element.answer) {
        
        CGRect body_tempRect = [element.answer boundingRectWithSize:CGSizeMake(CGRectGetWidth([[UIScreen mainScreen] bounds]) - 16, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14],NSParagraphStyleAttributeName : paragraphStyle} context:nil];
        float body_addHeight = body_tempRect.size.height > 20 ? body_tempRect.size.height - 20 : 20;
        addHeight = 10 + body_addHeight + addHeight;
    }
    for (DDQuestionAnswerExplanation * explan in element.explanation) {
        if ([explan.type isEqualToString:@"TEXT"]) {
            //addHeight += 30;
            //ruanch - bug 文字会被重叠
            CGRect body_tempRect = [explan.text boundingRectWithSize:CGSizeMake(CGRectGetWidth([[UIScreen mainScreen] bounds]) - 16, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin  attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14],NSParagraphStyleAttributeName : paragraphStyle} context:nil];
            addHeight += body_tempRect.size.height;
            NSLog(@"%f",CGRectGetWidth([[UIScreen mainScreen] bounds]));
        }else if ([explan.type isEqualToString:@"IMAGE"]){
            addHeight += 140;
        }
    }

    if (shareUser.userInfo.uid.integerValue != element.uid.integerValue) {
        addHeight += 30;
    }

    tempSize.width = self.view.frame.size.width;
    tempSize.height = 60 + addHeight;

    if (element.info_isShowList.boolValue == YES) {//展开的列表的cgsize
        float totalHeight = 50.0;
        for (int i = 0; i < element.info_exFollowAsk.list.count; i++) {
            DDQuestionAnswerReplyCell * tempModel = element.info_exFollowAsk.list[i];
            totalHeight += 50;
            for (DDQuestionAnswerReplyContent * content in tempModel.content) {
                if ([content.type isEqualToString:@"TEXT"]) {
                    CGRect tempRect = [content.text boundingRectWithSize:CGSizeMake(CGRectGetWidth([[UIScreen mainScreen] bounds]) - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14],NSParagraphStyleAttributeName : paragraphStyle} context:nil];
                    totalHeight += tempRect.size.height;
                }else if ([content.type isEqualToString:@"IMAGE"]){
                    totalHeight += 210+50;
                }else if ([content.type isEqualToString:@"VOICE"]){
                    totalHeight += 30;
                }


            }
        }
        tempSize.height = tempSize.height + totalHeight;
    }


    return tempSize;
}

-(CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    BOOL isHaveImage = NO;
    float addHeight = 0;

    for (DDModelMyQuetionsListElement_answerInfo_body * tempBody in self.info_detailInfo.info_body) {
        if ([tempBody.info_type isEqualToString:@"IMAGE"]){
            isHaveImage = YES;
        }else if([tempBody.info_type isEqualToString:@"TEXT"]){
            CGRect tempRect = [tempBody.info_text boundingRectWithSize:CGSizeMake(self.view.frame.size.width - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15],NSParagraphStyleAttributeName : paragraphStyle} context:nil];

            addHeight += (tempRect.size.height - 21);
            addHeight += 5;
        }
    }

    if (isHaveImage == YES) {
        addHeight = 100;
    }

    if (self.info_detailInfo.info_typeName) {
        addHeight += 30;
    }

    NSInteger optionsCount = self.info_detailInfo.info_options.count;
    float temp1 = 0;
    CGFloat heightOfContentOptions = 55 * optionsCount;
    
//    for (DDModelMyQuetionsListElement_answerInfo_option *option in self.info_detailInfo.info_options) {
//        
//    }

    for (int i = 0; i < self.info_detailInfo.info_options.count; i++) {
        DDModelMyQuetionsListElement_answerInfo_option * singleOption = self.info_detailInfo.info_options[i];
        BOOL addText = NO;
        BOOL addImage = NO;
        CGFloat temp2 = 0;
        for (NSInteger j = 0; j < singleOption.info_content.count; j++) {
            DDModelMyQuetionsListElement_answerInfo_body * optionElement = singleOption.info_content[j];
            if ([optionElement.info_type isEqualToString:@"TEXT"]) {
                addText = YES;
                CGRect tempRect = [optionElement.info_text boundingRectWithSize:CGSizeMake(CGRectGetWidth([[UIScreen mainScreen]bounds])-65, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSParagraphStyleAttributeName : paragraphStyle} context:nil];
                    temp2 += tempRect.size.height;
            }else if ([optionElement.info_type isEqualToString:@"IMAGE"]){
                addImage = YES;
            }
            
        }
//        if (addText == YES) {
            if (temp2 > 55) {
                temp1 += temp2;
            }else{
                temp1 += 55;
            }
//        }
        if (addImage) {
            temp1 += 35;
        }
        
   
    }
    
    addHeight +=  temp1;

    CGSize size = {self.view.frame.size.width, 120 + addHeight};
    return size;
}

- (CGSize)autoLabelString:(UIView *)view string:(NSString *)s
{
    UIFont *font = [UIFont fontWithName:@"Arial" size:17];
    //设置一个行高上限
    CGSize size = CGSizeMake(view.frame.size.width - 10,2000);
    //计算实际frame大小，并将label的frame变成实际大小
    CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
    return labelsize;
}


- (IBAction)btnClick_alert_cancel:(id)sender {
    self.contentOfAlert.hidden = YES;
    choosedStars = 0;
}
- (IBAction)btnClick_alert_confirm:(id)sender {
    self.contentOfAlert.hidden = YES;
    if (choosedStars == 0) {

    }else{
        [self showHUD:@""];
        NSDictionary * paramDic = @{@"answerId" : hold_rating.id,
                                    @"score" : [NSNumber numberWithInteger:choosedStars]};
        [client mainQuestionAnswerEvaluate:paramDic completionBlock:^(BOOL isSuccess, NSString *message, NSString *status, id object) {
            [array_showList removeAllObjects];
            currentPage = 0;
            [self hideHUD];

            [self.myCollectionView footerBeginRefreshing];
        }];
    }

}


#pragma mark - DDMyQuestionDetailCollectionViewCellDelegate
-(void)starRateWithCell:(DDMyQuestionDetailCollectionViewCell *)tempCell{
    NSIndexPath * indexPath = [self.myCollectionView indexPathForCell:tempCell];
    choosedStars = 5;
    hold_rating = array_showList[indexPath.row];
    
    self.contentOfAlert.hidden = NO;

}
-(void)followAnswerWithCell:(DDMyQuestionDetailCollectionViewCell *)tempCell{
    NSIndexPath * indexPath = [self.myCollectionView indexPathForCell:tempCell];
    hold_followAnswer = array_showList[indexPath.row];
    DDQuestionFollowAnswerViewController * vc = [[DDQuestionFollowAnswerViewController alloc]init];
    vc.info_element = hold_followAnswer;
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)adoptWithCell:(DDMyQuestionDetailCollectionViewCell *)tempCell{
    NSIndexPath * indexPath = [self.myCollectionView indexPathForCell:tempCell];
    hold_adopt = array_showList[indexPath.row];
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"采纳答案" message:@"" delegate:self cancelButtonTitle:@"拒绝" otherButtonTitles:@"采纳", nil];
    [alert show];
}

-(void)openOrCloseFollowAsk:(DDMyQuestionDetailCollectionViewCell *)tempCell{
    NSIndexPath * indexPath = [self.myCollectionView indexPathForCell:tempCell];

    __block DDQuestionAnswerListCell * element = array_showList[indexPath.row];
    element.info_isShowList = [NSNumber numberWithBool:!element.info_isShowList.boolValue ];
    if (element.info_isShowList.boolValue == YES) {
        [self showHUD:@"加载数据..."];
        NSDictionary * tempDic = @{@"answerId" : element.id ,
                                   @"pageIndex" : [NSNumber numberWithInteger:0],
                                   @"pageSize" : [NSNumber numberWithInteger:100]};
        __weak DDMyQuestionDetailTempViewController * weakSelf = self;
        [client mainQuestionReplyList:tempDic completionBlock:^(BOOL isSuccess, NSString *message, NSString *status, id object) {
            DDQuestionAnswerReply * model = object;
            NSMutableArray * addArray = [NSMutableArray array];
            for (DDQuestionAnswerReplyCell *cell in model.list) {
                [addArray addObject:cell];
                if (cell.children.count > 0) {
                    DDQuestionAnswerReplyCell *childer = cell.children[0];
                    [addArray addObject:childer];
                }
            }
            model.list =  addArray;
            element.info_exFollowAsk = model;
//            [weakSelf.myCollectionView reloadData];
            [weakSelf.myCollectionView reloadItemsAtIndexPaths:@[indexPath]];
            [weakSelf hideHUD];
        }];
    }else{
        [self.myCollectionView reloadItemsAtIndexPaths:@[indexPath]];
        [self.myCollectionView reloadData];
    }

}

- (void)starRateView:(CWStarRateView *)starRateView scroePercentDidChange:(CGFloat)newScorePercent{
    choosedStars = newScorePercent * 5;
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if ([alertView.title isEqualToString:@"采纳答案"]) {
        NSDictionary * tempDic = nil;
        if (buttonIndex == 1) {
            tempDic =  @{
                         @"answerId" : hold_adopt.id,
                         @"result" : [NSNumber numberWithBool:YES],
                         };
        }else{
            tempDic =  @{
                         @"answerId" : hold_adopt.id,
                         @"result" : [NSNumber numberWithBool:NO],
                         };
        }
        [self showHUD:@""];
        __weak DDMyQuestionDetailTempViewController * weakSelf = self;
        [client mainQuestionAnswerAdopt:tempDic completionBlock:^(BOOL isSuccess, NSString *message, NSString *status, id object) {
            [weakSelf hideHUD];
            [weakSelf refreshData];
        }];
        
        
    }
}

#pragma mark - DDMyQuestionDetailCollectionReusableViewDelegate
-(void)imageViewClicked:(NSString *)imageURL{
    if (imageURL) {
        holdString_PhotoBrowser = imageURL;
        MWPhotoBrowser * browser = [[MWPhotoBrowser alloc]initWithDelegate:self];
        browser.displayActionButton = NO;
        [self.navigationController pushViewController:browser animated:YES];
    }
}

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser{
    return 1;
}
- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index{
    
    MWPhoto * photo = [[MWPhoto alloc]initWithURL:[NSURL URLWithString:holdString_PhotoBrowser]];
    return photo;
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
